package com.kevin.kitchenshow2.adapter;

import java.util.List;

import com.kevin.kitchenshow2.R;
import com.kevin.kitchenshow2.entity.Category;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryAdapter extends BaseAdapter {
	private List<Category> lstCategory;
	private Context context;
	private LayoutInflater inflater;

	public CategoryAdapter() {

	}

	public CategoryAdapter(Context context, List<Category> lstCategory) {
		this.context = context;
		this.lstCategory = lstCategory;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lstCategory == null ? 0 : lstCategory.size();
	}

	@Override
	public Category getItem(int pos) {
		// TODO Auto-generated method stub
		return pos < 0 || lstCategory == null || pos >= lstCategory.size() ? null
				: lstCategory.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		CategoryHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.category_list_item, null);
			holder = new CategoryHolder();
			holder.imageView = (ImageView) convertView
					.findViewById(R.id.imvCategory);
			holder.txtName = (TextView) convertView
					.findViewById(R.id.txvCategory);
			// holder.status.
			convertView.setTag(holder);
		} else {
			holder = (CategoryHolder) convertView.getTag();
		}

		if (lstCategory != null && position >= 0
				&& position < lstCategory.size()) {
			holder.imageView.setImageDrawable(lstCategory.get(position)
					.getImage());
			holder.txtName.setText(lstCategory.get(position).getName());
		}

		// holder.txvInfo.setText(lstItems.get(position).getCountryid());
		return convertView;

	}

}
